/**
 * jQuery for WP-Kommentaromat
 * version 0.2
 */

//jQuery.noconflict();

jQuery(document).ready( function($){

	var wpKommentaromat = {
			comment_textarea: 'textarea#comment',
			kommentaromat_container: '#wpkommentaromat',
			pre_comment: "******************KOMMENTAROMAT**********************\n",
			after_comment: "\n*****************/KOMMENTAROMAT**********************\n",
					
			init: function(){
				var a = this;
				
				// is the kommentaromat container present?
				var container_id = $('body').find( a.kommentaromat_container ).attr( 'id' );
				
				// we can't find the container. stop here because maybe it is not a single page
				if( undefined === container_id ){
					return false;
				}
				
				// register click-events
				$( '.wpkommentaromat_add' ).click( function(){ a.addComment( $(this) ) });
				$( '.wpkommentaromat_del' ).click( function(){ a.delComment() });
			},
			
			addComment: function(e){
				var a = this;
				
				if( '' != e.val() ){
					var c = $(a.comment_textarea).val();
					var comment = c + a.pre_comment + e.val() + a.after_comment;
					
					$(a.comment_textarea).val( comment );
				}
				
			},
			
			delComment: function(){
				var a = this;
				
				$(a.comment_textarea).val('');
			}
			
	};
	
	wpKommentaromat.init();
});